﻿using System.Collections.Generic;
namespace hCommand {
    /**
   *┌────────────────────────────────────────────────┐
   *│　描    述：DoubleLocEngine                                                    
   *│　作    者：sgj                                              
   *│　版    本：1.0                                              
   *│　创建时间：2020/9/9 17:28:44                        
   *└────────────────────────────────────────────────┘
   **/
    public class StockDetailUtil<CS, CSD> where CS : AbsCoreStock where CSD : AbsCoreStockDetail {
        public static List<ShelfDto<CSD>> marginStock(List<CSD> list) {
            List<ShelfDto<CSD>> detalss = new List<ShelfDto<CSD>>();
            foreach( CSD csd in list ) {
                addCsd(csd ,detalss);
            }

            return detalss;
        }

        static void addCsd(CSD csd ,List<ShelfDto<CSD>> detalss) {
            foreach( ShelfDto<CSD> dto in detalss ) {
                if( dto.add(csd) ) {
                    return;
                }
            }
            LocStockDto<CSD> shallow;
            LocStockDto<CSD> deep;
            if( csd.rLocId % 10 == 2 ) {
                long shallowLocId = ( long ) csd.rLocId - 1L;
                shallow = new LocStockDto<CSD>() { locId = shallowLocId ,stockDetails = new List<CSD>() { } };
                deep = new LocStockDto<CSD>() { locId = csd.rLocId ,stockDetails = new List<CSD>() { csd } };
            } else {
                var deepLocId = ( long ) csd.rLocId + 1L;
                shallow = new LocStockDto<CSD>() { locId = csd.rLocId ,stockDetails = new List<CSD>() { csd } };
                deep = new LocStockDto<CSD>() { locId = deepLocId ,stockDetails = new List<CSD>() { } };
            }
            detalss.Add(new ShelfDto<CSD> {
                scr = ( int ) (csd.rLocId / 10) ,
                deep = deep ,
                shallow = shallow
            });
            ;

        }
        static public void addDeffCsd(CSD csd ,List<ShelfDto<CSD>> detalss) {
            foreach( ShelfDto<CSD> dto in detalss ) {
                LocStockDto<CSD> shallow = dto.shallow;
                if( shallow.locId == csd.rLocId ) {
                    shallow.stockDetails.Add(csd);
                    shallow.deff = true;
                    return;
                }
                LocStockDto<CSD> deep = dto.deep;
                if( deep.locId == csd.rLocId ) {
                    deep.stockDetails.Add(csd);
                    deep.deff = true;
                }
            }

        }
    }
}
